layui.use(['table', 'jquery','element','layer','form','layedit','upload'], function () {
    var table = layui.table;
    var $ = layui.jquery;
    var element = layui.element;
    var layer = layui.layer;
    var form = layui.form;
    var layedit = layui.layedit;
    var upload = layui.upload;
    //第一个实例
    table.render({
        elem: '#table',
        height: 600,
        toolbar :'#toolbar',
        defaultToolbar : []
        , url: ctx + '/eng/user/remain/apply/listPage' //数据接口
        , page: true
        , cols: [[
            {field: 'userName', title: '客户姓名', align: 'center',width:'13%'}
            , {field: 'amount', title: '金额', align: 'center',width:'13%'}
            , {field: 'createTime', title: '申请时间', align: 'center',width:'24%'}
            //, {field: 'verifyTime', title: '审核时间', align: 'center',width:'19%'}
            //, {field: 'verifyName', title: '审核人', align: 'center',width:'10%'}
            , {field: 'status', title: '提现状态', align: 'center',width:'10%',templet : function(d){
                    if(d.status == 1){
                        return "进行中";
                    }else if(d.status == 2){
                        return "提现成功";
                    }
                    return "提现失败";
                }}
            , {field: 'sn', title: '交易流水号', align: 'center',width:'24%'},
            {field: 'remark', title: '备注', align: 'center',width:'10%'}
            // , {field: 'ops', title: '操作', width: '30%', align: 'center',toolbar: '#tool'}
        ]]
    });

    // tool
    table.on('tool(table)', function(obj){
        var data = obj.data;
        var layEvent = obj.event;

        if(layEvent === 'verify'){
            verify(data);
        }
    });


    // 审核提现记录
    function verify(data){
        layer.confirm('选择该记录是否通过?',{
            btn :['通过','驳回']
        }, function(index){
            //通过
            $.ajax({
                url : ctx+"/eng/user/remain/apply/verifyOK",
                data :{
                    id : data.id
                },
                async : false,
                success : function(res){
                    if(res.success){
                        layer.close(index);
                        layer.msg(res.msg,{icon:1});
                        table.reload('table');
                    }else{
                        layer.msg(res.msg,{icon:2});
                    }
                }
            });


        },function(index){
            $.ajax({
                url : ctx+"/eng/user/remain/apply/verifyFail",
                data :{
                    id : data.id
                },
                async : false,
                success : function(res){
                    if(res.success){
                        layer.close(index);
                        layer.msg(res.msg,{icon:1});
                        table.reload('table');
                    }else{
                        layer.msg(res.msg,{icon:2});
                    }
                }
            });
        });
    }
});